7 typedef pair
<char, int> hole
;
10 bool operator() (const hole
&a
, const hole
&b
) const{
11 return (a
.second
< b
.second
) ||
12 (a
.second
== b
.second
&& a
.first
> b
.first
);
20 int di
[] = {-1, 0, 1, 0};
21 int dj
[] = { 0, 1, 0, -1};
23 int dfs(const int &i
,const int &j
){
26 for (int k
= 0; k
<4; ++k
){
30 if (0 <= iNew
&& iNew
< r
&&
31 0 <= jNew
&& jNew
< c
&&
32 !visited
[iNew
][jNew
] &&
33 g
[i
][j
] == g
[iNew
][jNew
]){
35 result
+= dfs(iNew
, jNew
);
44 while (cin
>> r
>> c
&& (r
| c
)){
45 for (int i
=0; i
<r
; ++i
){
46 for (int j
=0; j
<c
; ++j
){
48 visited
[i
][j
] = false;
52 multiset
<hole
, holeCompare
> holes
;
53 for (int i
=0; i
<r
; ++i
){
54 for (int j
=0; j
<c
; ++j
){
55 if (!visited
[i
][j
] && g
[i
][j
] != '.'){
56 holes
.insert(hole(g
[i
][j
], dfs(i
,j
)));
60 cout
<< "Problem " << problemNo
++ << ":" << endl
;
61 for (multiset
<hole
>::reverse_iterator i
= holes
.rbegin(); i
!= holes
.rend(); ++i
){
62 cout
<< i
->first
<< " " << i
->second
<< endl
;